package cn.com.surker.lab.service.impl;

import cn.com.surker.base.strength.dao.BaseStrengthDao;
import cn.com.surker.base.strength.dao.BaseStrengthLevelDosageDao;
import cn.com.surker.base.strength.entity.BaseStrength;
import cn.com.surker.base.strength.entity.BaseStrengthLevelDosage;
import cn.com.surker.common.MessageCenterException;
import cn.com.surker.enums.material.SysMaterialTypeEnum;
import cn.com.surker.enums.system.AnalysisTypeEnum;
import cn.com.surker.lab.dao.LabLevelOptimizeMaterialDao;
import cn.com.surker.lab.entity.LabLevelOptimize;
import cn.com.surker.lab.dao.LabLevelOptimizeDao;
import cn.com.surker.lab.entity.LabLevelOptimizeMaterial;
import cn.com.surker.lab.service.LabLevelOptimizeService;
import cn.com.surker.lab.util.LabLevelUtil;
import cn.com.surker.lab.util.LevelExcelUtil;
import cn.com.surker.lab.vo.LabLevelOptimizeVo;
import cn.com.surker.oa.dao.OaEnclosureDao;
import cn.com.surker.oa.dao.OaMaterialDao;
import cn.com.surker.oa.entity.OaEnclosure;
import cn.com.surker.oa.entity.OaMaterial;
import cn.com.surker.spring.RestResultDto;
import cn.com.surker.system.dao.SysAnalysisConfigDao;
import cn.com.surker.system.entity.SysAnalysisConfig;
import cn.com.surker.util.DateUtil;
import cn.com.surker.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * <p>
 * 强度等级优化表(用于上传到检查平台) 服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-09-23
 */
@Service
public class LabLevelOptimizeServiceImpl extends ServiceImpl<LabLevelOptimizeDao, LabLevelOptimize> implements LabLevelOptimizeService {

	@Resource
	private LabLevelOptimizeDao labLevelOptimizeDao;
	@Resource
	private LabLevelOptimizeMaterialDao levelOptimizeMaterialDao;
	@Resource
	private OaEnclosureDao enclosureDao;
	@Resource
	private SysAnalysisConfigDao analysisConfigDao;
	@Resource
	private BaseStrengthDao baseStrengthDao;
	@Resource
	private OaMaterialDao materialDao;
	@Resource
	private BaseStrengthLevelDosageDao strengthLevelDosageDao;

	/**
	 * 分页查询配合比列表
	 * @param searchVal
	 * @param strengthId
	 * @param offset
	 * @param limit
	 * @return
	 */
	public IPage findPage(String searchVal, Long strengthId, Integer status, Integer offset, Integer limit) {
		PageHelper.offsetPage(offset, limit);
		QueryWrapper<LabLevelOptimize> query = new QueryWrapper<>();
		if (StringUtils.isNull(status))
			status = 0;
		if (!StringUtils.isNull(status))
			query.eq("enable", status);
		if (!StringUtils.isNull(strengthId))
			query.eq("strength_id", strengthId);
		if (!StringUtils.isNull(searchVal)) {
			query.and(orderWrapper -> orderWrapper.like("code", searchVal).or()
					.like("season", searchVal).or().like("remark", searchVal));
		}

		query.orderByDesc("create_time");

		IPage<LabLevelOptimize> iPage = labLevelOptimizeDao.selectPage(new Page<>((offset + limit) /limit, limit), query);
		/**分页插件**/
		if (!StringUtils.isNull(iPage.getRecords())) {
			PageInfo pageInfo = new PageInfo(iPage.getRecords());
			if (!StringUtils.isNull(pageInfo.getTotal()))
				iPage.setTotal(pageInfo.getTotal());
		}
		return iPage;
	}

	/**
	 * 保存施工配比
	 * @param labLevelConstruct
	 * @return
	 */
	public RestResultDto saveLevel(LabLevelOptimize labLevelConstruct) {
		if (labLevelConstruct == null)
			throw new MessageCenterException("参数错误");
		if (StringUtils.isNull(labLevelConstruct.getCode()))
			throw new MessageCenterException("配合比编号为空");
		String levelCode = labLevelConstruct.getCode().toUpperCase().replaceAll(" ", "").replaceAll("（", "(")
				.replaceAll("）", ")").replaceAll("【", "[").replaceAll("】", "]");
		labLevelConstruct.setCode(levelCode);
		QueryWrapper<LabLevelOptimize> query = new QueryWrapper<>();
		query.eq("status", 0);
		query.eq("code", labLevelConstruct.getCode());
		labLevelConstruct.setCreateTime(new Date());
		Integer total = labLevelOptimizeDao.selectCount(query);
		if (total > 0)
			throw new MessageCenterException("配合比编号已存在");
		Integer code = labLevelOptimizeDao.insert(labLevelConstruct);
		if (code > 0)
			return RestResultDto.success("保存成功", labLevelConstruct);
		throw new MessageCenterException("保存失败");
	}

	/**
	 * 修改施工配比
	 * @param labLevelConstruct
	 * @return
	 */
	public RestResultDto updateLevel(LabLevelOptimize labLevelConstruct) {
		if (labLevelConstruct == null || StringUtils.isNull(labLevelConstruct.getId()))
			throw new MessageCenterException("参数错误");
		LabLevelOptimize construct = labLevelOptimizeDao.selectById(labLevelConstruct.getId());
		if (construct == null || construct.getStatus().intValue() == 1)
			throw new MessageCenterException("业务数据不存在或已被禁用");
		if (!StringUtils.isNull(labLevelConstruct.getCode()) && !labLevelConstruct.getCode().equals(construct.getCode())) {
			String levelCode = labLevelConstruct.getCode().toUpperCase().replaceAll(" ", "").replaceAll("（", "(")
					.replaceAll("）", ")").replaceAll("【", "[").replaceAll("】", "]");
			QueryWrapper<LabLevelOptimize> queryWrapper = new QueryWrapper<>();
			queryWrapper.eq("status", 0);
			queryWrapper.eq("code", levelCode);
			Integer total = labLevelOptimizeDao.selectCount(queryWrapper);
			if (total > 0)
				throw new MessageCenterException("施工配比代号已存在");
			construct.setCode(levelCode);
		}
		labLevelConstruct.setUpdateTime(new Date());
		Integer code = labLevelOptimizeDao.updateById(labLevelConstruct);
		if (code > 0)
			return RestResultDto.success("更新成功", labLevelConstruct);
		throw new MessageCenterException("更新失败");
	}

	/**
	 * 更新状态
	 * @param id
	 * @param status
	 * @param remark
	 * @param creator
	 * @return
	 */
	public RestResultDto updateStatus(Long id, Integer status, String remark, String creator) {
		if (StringUtils.isAllParamNull(id, status))
			throw new MessageCenterException("参数错误");
		LabLevelOptimize construct = labLevelOptimizeDao.selectById(id);
		if (construct == null)
			throw new MessageCenterException("业务数据不存在");
		construct.setEnable(status);
		construct.setUpdateTime(new Date());
		construct.setUpdator(creator);
		if (!StringUtils.isNull(remark))
			construct.setRemark(remark);
		Integer code = labLevelOptimizeDao.updateById(construct);
		if (code > 0)
			return RestResultDto.success("更新成功");
		throw new MessageCenterException("更新失败");
	}

	/**
	 * 解析标准配比Excel
	 * @param enclosureId
	 * @return
	 */
	public RestResultDto analysisOptimize(Long orgId, Long enclosureId, String creator) {
		if (StringUtils.isNull(enclosureId))
			throw new MessageCenterException("解析Excel参数错误");
		OaEnclosure enclosure = enclosureDao.selectById(enclosureId);
		if (enclosure == null || enclosure.getStatus() == 1)
			throw new MessageCenterException("解析文件不存在");

		QueryWrapper<SysAnalysisConfig> query = new QueryWrapper<>();
		query.eq("status", 0);
		query.in("type", AnalysisTypeEnum.HNTPHB.getCode(), AnalysisTypeEnum.SJPHB.getCode());
		List<SysAnalysisConfig> analysisConfigList = analysisConfigDao.selectList(query);//查询配置列
		if (analysisConfigList == null || analysisConfigList.size() == 0)
			throw new MessageCenterException("解析配置列信息不存在");
		Map<String, Integer> hntConfigMap = new HashMap<>();
		Map<String, Integer> sjConfigMap = new HashMap<>();
		List<String> hntKeyList = new ArrayList<>();
		List<String> sjKeyList = new ArrayList<>();
		for (int i = 0; i < analysisConfigList.size(); i++) {
			SysAnalysisConfig analysisConfig = analysisConfigList.get(i);
			if (analysisConfig.getType() != null) {
				if (analysisConfig.getType().intValue() == AnalysisTypeEnum.HNTPHB.getCode()) {
					hntKeyList.add(analysisConfig.getName());//添加列名称
					hntConfigMap.put(analysisConfig.getName(), analysisConfig.getDataType());
				} else if (analysisConfig.getType().intValue() == AnalysisTypeEnum.SJPHB.getCode()) {
					sjKeyList.add(analysisConfig.getName());//添加砂浆列名称
					sjConfigMap.put(analysisConfig.getName(), analysisConfig.getDataType());
				}
			}
		}
		QueryWrapper<BaseStrength> strengthQuery = new QueryWrapper<>();
		strengthQuery.eq("status", 0);
		strengthQuery.inSql("id", "select strength_id from base_strength_org where status = 0 and org_id = " + orgId);
		List<BaseStrength> strengthList = baseStrengthDao.selectList(strengthQuery);
		if (strengthList == null || strengthList.size() == 0)
			throw new MessageCenterException("没有任何标号信息");
		QueryWrapper<OaMaterial> materialQuery = new QueryWrapper<>();
		materialQuery.eq("status", 0);
//		materialQuery.inSql("id", "select material_id from main_material where status = 0 and org_id = " + orgId);
		List<OaMaterial> materialList = materialDao.selectList(materialQuery);
		if (strengthList == null || strengthList.size() == 0)
			throw new MessageCenterException("没有任何材料信息");
		QueryWrapper<BaseStrengthLevelDosage> dosageQuery = new QueryWrapper<>();
		dosageQuery.eq("status", 0);
		dosageQuery.eq("org_id", orgId);
		List<BaseStrengthLevelDosage> dosageList = strengthLevelDosageDao.selectList(dosageQuery);
		Map<String, BaseStrengthLevelDosage> strengthDosageMap = new HashMap<>();
		Map<String, BaseStrength> strengthMap = new HashMap<>();
		Map<String, OaMaterial> materialMap = new HashMap<>();
		for (int i = 0; i < strengthList.size(); i++) {//强度
			BaseStrength baseStrength = strengthList.get(i);
			strengthMap.put(baseStrength.getStrength(), baseStrength);
		}
		for (int i = 0; i < materialList.size(); i++) {//配比材料
			OaMaterial oaMaterial = materialList.get(i);
			materialMap.put(oaMaterial.getFullName(), oaMaterial);
		}
		if (dosageList == null || dosageList.size() == 0) {//强度区间
			BaseStrengthLevelDosage levelDosage = new BaseStrengthLevelDosage(orgId, 0l, "默认强度", 2300.0, 2400.0);
			strengthDosageMap.put("0", levelDosage);
		} else {
			for (int i = 0; i < dosageList.size(); i++) {
				BaseStrengthLevelDosage levelDosage = dosageList.get(i);
				strengthDosageMap.put(levelDosage.getStrengthId() + "", levelDosage);
			}
		}
		InputStream inputStream = null;
		String message = "";
		try {
			inputStream=new FileInputStream(enclosure.getFilePath());
			Workbook workbook = new XSSFWorkbook(inputStream);
			Integer numberOfSheets = workbook.getNumberOfSheets();
			for (int i = 0; i < numberOfSheets; i++) {
				Sheet baseSheet = workbook.getSheetAt(i);
				String sheetName = baseSheet.getSheetName();
				if (!StringUtils.isNull(sheetName)) {
					sheetName = sheetName.replaceAll(" ", "").replaceAll("\n", "")
							.replaceAll("（", "(").replaceAll("）", ")");
					if (sheetName.equals("混凝土")) {
						List<Map<String, Object>> resultList = LevelExcelUtil.analysisLevelSheet(baseSheet, hntKeyList);
						message += saveOptimize(orgId, resultList, materialMap,strengthMap, strengthDosageMap,
								AnalysisTypeEnum.HNTPHB.getCode(), creator);
					} else if (sheetName.equals("砂浆")) {
						List<Map<String, Object>> resultList = LevelExcelUtil.analysisLevelSheet(baseSheet, sjKeyList);
						message += saveOptimize(orgId, resultList, materialMap,strengthMap, strengthDosageMap,
								AnalysisTypeEnum.SJPHB.getCode(), creator);
					} else {
						throw new MessageCenterException("未获取到混凝土或砂浆的sheet文件,不合法sheet名称：" + sheetName);
					}
				}
			}
			RestResultDto dto = RestResultDto.success("解析完成~！");
			if (!StringUtils.isNull(message))
				dto.setMsg(message);
			return dto;
		} catch (Exception e) {
			e.printStackTrace();
			throw new MessageCenterException("解析异常");
		} finally {
			if (inputStream != null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}

	}
	public static void main(String[] args){
		System.out.println(DateUtil.convertDate("2025年1月16日 03:00:00", "yyyy年MM月dd日 03:00:00"));
	}
	/**
	 * 保存标准配合比编号
	 * @param resultList
	 * @param type
	 */
	private String saveOptimize(Long orgId, List<Map<String, Object>> resultList,Map<String, OaMaterial> materialMap,
								Map<String, BaseStrength> strengthMap, Map<String, BaseStrengthLevelDosage> strengthDosageMap,
								Integer type, String creator) {
		if (resultList == null || resultList.size() == 0)
			return "";
		String message = "";
		Date nowDate = new Date();
//		String startTime_ = DateUtil.convertString(DateUtil.convertBeforeDayDate(nowDate, 60));
//		String endTime_ = DateUtil.convertString(nowDate);
//		Long sn
		for (int i = 0; i < resultList.size(); i++) {
			Map<String, Object> map = resultList.get(i);
			String remark = StringUtils.convertString(map.get("水泥品种"));
			String labCode = StringUtils.convertString(map.get("配合比编号"));
			String strength = StringUtils.convertString(map.get("强度等级"));
			Double snDosage = StringUtils.convertDouble(map.get("水泥"));
			Double sDosage = StringUtils.convertDouble(map.get("水"));
			Double mhDosage = StringUtils.convertDouble(map.get("粉煤灰"));
			Double kfDosage = StringUtils.convertDouble(map.get("矿渣粉"));
			Double chDosage = StringUtils.formatDouble(mhDosage + kfDosage, 1);
			String startTime = StringUtils.convertString(map.get("配制日期"));
			Double wjjDosage = StringUtils.convertDouble(map.get("外加剂"));
			Double pzjDosage = StringUtils.convertDouble(map.get("膨胀剂"));
			Double cjDosage = 0.0;
			Double xjDosage = 0.0;
			Double qtDosage = 0.0;
			Double zsjDosage = 0.0;
			Double tjjDosage = 0.0;
			if (type == AnalysisTypeEnum.HNTPHB.getCode()) {//混凝土
				xjDosage = StringUtils.convertDouble(map.get("细骨料"));
				cjDosage = StringUtils.convertDouble(map.get("粗骨料"));
				qtDosage = StringUtils.convertDouble(map.get("其他"));
			} else if (type == AnalysisTypeEnum.SJPHB.getCode()) {//砂浆
				xjDosage = StringUtils.convertDouble(map.get("机制砂"));
				zsjDosage = StringUtils.convertDouble(map.get("增塑剂"));
				tjjDosage = StringUtils.convertDouble(map.get("调节剂"));
			}
            if (StringUtils.isNull(strength) || StringUtils.isNull(labCode))
                continue;
			LabLevelOptimize existOptimize = labLevelOptimizeDao.existOptimize(orgId, labCode);

			if (existOptimize != null) {
//				message += "编号：" + code + "已存在,";
				continue;
			}
			Double wjjDosage1 = StringUtils.formatDouble(zsjDosage + tjjDosage + wjjDosage + pzjDosage, 1);
			Double sumDosage = StringUtils.formatDouble(snDosage + xjDosage + cjDosage + sDosage + wjjDosage1
					+ pzjDosage + mhDosage + kfDosage + qtDosage,1);
			Date startDate = null;
			if (!StringUtils.isNull(startTime)) {
				if (startTime.indexOf(".") != -1)
					startDate = DateUtil.convertDate(startTime, "yyyy.MM.dd");
				else if (startTime.indexOf("-") != -1)
					startDate = DateUtil.convertDate(startTime, "yyyy-MM-dd");
				else if (startTime.indexOf("年") != -1)
					startDate = DateUtil.convertDate(startTime, "yyyy年MM月dd日");
			} else {
				startDate = nowDate;
			}
			BaseStrength baseStrength = strengthMap.get(strength);
			String slump = StringUtils.convertString(map.get("坍落度"));
			if (!strengthMap.containsKey(strength)) {
				message += strength + "未匹配到标号,";
				continue;
			}
			BaseStrengthLevelDosage levelDosage = null;
			if (strengthDosageMap.containsKey(baseStrength.getId())) {
				levelDosage = strengthDosageMap.get(baseStrength.getId() + "");
			} else {
				levelDosage = new BaseStrengthLevelDosage(orgId, 0l, "默认强度", 2300.0, 2400.0);
			}
			Double density = 0.0;//密度
			String ratio1 = LabLevelUtil.shRatio(sDosage, snDosage);//水灰
			String ratio2 = LabLevelUtil.sjRatio(sDosage, snDosage, chDosage);//水胶
			String mixRatio = LabLevelUtil.phbRatio(snDosage, xjDosage, cjDosage, chDosage, wjjDosage, sDosage);//配合比
			Double sandRate = LabLevelUtil.slRatio(xjDosage, cjDosage);
			LabLevelOptimize optimize = new LabLevelOptimize(orgId, "", baseStrength.getId(), slump, slump,
					startDate, "", startDate, null, 0, 0, 30, sumDosage, levelDosage.getMinDosage(),
					levelDosage.getMaxDosage(), density, ratio1, ratio2, mixRatio, sandRate, 0, 2.0);
			optimize.setCreator(creator);
			optimize.setLabCode(labCode);
			optimize.setStatus(0);
			optimize.setCreateTime(nowDate);
			optimize.setRemark(remark);
			Integer resultCode = labLevelOptimizeDao.insert(optimize);
			Long optimizeId = optimize.getId();
			if (resultCode < 1) { //组装配合比材料
				message += strength + "保存标准配比异常";
				continue;
			}
			List<LabLevelOptimizeMaterial> optimizeMaterialList = new ArrayList<>();
			LabLevelOptimizeMaterial snMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
					SysMaterialTypeEnum.SN.getCode().longValue(), SysMaterialTypeEnum.SN.getDescription(),
					445l, "璧山冀东水泥[P.O42.5R]", snDosage, 0 ,nowDate);
			LabLevelOptimizeMaterial xjMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
					SysMaterialTypeEnum.XJL.getCode().longValue(), SysMaterialTypeEnum.XJL.getDescription(),
					735l, "山石[机制砂]", xjDosage, 0 ,nowDate);
			optimizeMaterialList.add(snMaterial);
			optimizeMaterialList.add(xjMaterial);
			LabLevelOptimizeMaterial sMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
					SysMaterialTypeEnum.SH.getCode().longValue(), SysMaterialTypeEnum.SH.getDescription(),
					515l, "水[水]", sDosage, 0 ,nowDate);
			optimizeMaterialList.add(sMaterial);
			if (wjjDosage > 0) {
				LabLevelOptimizeMaterial wjjMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
						SysMaterialTypeEnum.WJJ.getCode().longValue(), SysMaterialTypeEnum.WJJ.getDescription(),
						507l, "外加剂[高浓]", wjjDosage, 0 ,nowDate);
				optimizeMaterialList.add(wjjMaterial);
			}
			if (pzjDosage > 0) {
				LabLevelOptimizeMaterial wjjMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
						SysMaterialTypeEnum.WJJ.getCode().longValue(), SysMaterialTypeEnum.WJJ.getDescription(),
						533l, "膨胀剂", pzjDosage, 0 ,nowDate);
				optimizeMaterialList.add(wjjMaterial);
			}
			if (mhDosage > 0) {
				LabLevelOptimizeMaterial mhMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
						SysMaterialTypeEnum.CHL.getCode().longValue(), SysMaterialTypeEnum.CHL.getDescription(),
						492l, "粉煤灰[Ⅱ级]", mhDosage, 0 ,nowDate);
				optimizeMaterialList.add(mhMaterial);
			}
			if (kfDosage > 0) {
				LabLevelOptimizeMaterial kfMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
						SysMaterialTypeEnum.CHL.getCode().longValue(), SysMaterialTypeEnum.CHL.getDescription(),
						722l, "祥众矿粉[S95]", kfDosage, 0 ,nowDate);
				optimizeMaterialList.add(kfMaterial);
			}
			if (type == AnalysisTypeEnum.HNTPHB.getCode()) {//混凝土
				if (strength.indexOf("细石") != -1) {
					LabLevelOptimizeMaterial cjMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
							SysMaterialTypeEnum.CJL.getCode().longValue(), SysMaterialTypeEnum.CJL.getDescription(),
							477l, "山石[0-1]", cjDosage, 0 ,nowDate);
					optimizeMaterialList.add(cjMaterial);
				} else {
					Double cjDosage1 = StringUtils.formatDouble(cjDosage * 0.4, 1);
					Double cjDosage2 = StringUtils.formatDouble(cjDosage * 0.6, 1);
					LabLevelOptimizeMaterial cjMaterial1 = new LabLevelOptimizeMaterial(orgId, optimizeId,
							SysMaterialTypeEnum.CJL.getCode().longValue(), SysMaterialTypeEnum.CJL.getDescription(),
							477l, "山石[0-1]", cjDosage1, 0 ,nowDate);
					LabLevelOptimizeMaterial cjMaterial2 = new LabLevelOptimizeMaterial(orgId, optimizeId,
							SysMaterialTypeEnum.CJL.getCode().longValue(), SysMaterialTypeEnum.CJL.getDescription(),
							476l, "山石[1-2]", cjDosage2, 0 ,nowDate);
					optimizeMaterialList.add(cjMaterial2);
					optimizeMaterialList.add(cjMaterial1);
				}
				if (qtDosage > 0) {
					LabLevelOptimizeMaterial qtMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
							SysMaterialTypeEnum.PZCL.getCode().longValue(), SysMaterialTypeEnum.PZCL.getDescription(),
							692l, "混凝土配重材料", qtDosage, 0 ,nowDate);
					optimizeMaterialList.add(qtMaterial);
				}
			} else if (type == AnalysisTypeEnum.SJPHB.getCode()) {//砂浆
				if (zsjDosage > 0) {
					LabLevelOptimizeMaterial wjjMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
							SysMaterialTypeEnum.WJJ.getCode().longValue(), SysMaterialTypeEnum.WJJ.getDescription(),
							512l, "砂浆增塑剂[.增塑剂]", zsjDosage, 0 ,nowDate);
					optimizeMaterialList.add(wjjMaterial);
				}
				if (tjjDosage > 0) {
					LabLevelOptimizeMaterial wjjMaterial = new LabLevelOptimizeMaterial(orgId, optimizeId,
							SysMaterialTypeEnum.WJJ.getCode().longValue(), SysMaterialTypeEnum.WJJ.getDescription(),
							511l, "砂浆调节剂[.调节剂]", tjjDosage, 0 ,nowDate);
					optimizeMaterialList.add(wjjMaterial);
				}
			}
			levelOptimizeMaterialDao.saveBatch(optimizeMaterialList);
		}
		return message;
	}

	public List<LabLevelOptimizeVo> findAll() {
		QueryWrapper<LabLevelOptimize> query = new QueryWrapper<>();
		query.eq("a.status", 0);
		query.orderByDesc("a.take_effect_date");
		List<LabLevelOptimizeVo> optimizeList = labLevelOptimizeDao.findOptimizeVo(query);

		return optimizeList;
	}

}